
/* 
 * Source name     : lab1_p1_cprog.c
 * Executable name : lab1_p1_cprog
 * Version         : 1.1
 * Created date    : 9/18/03
 * Last update     : 1/28/05
 * Author          : Jason Fritts, Roger Chamberlain
 * Description     : 
 * 
 * Build using this command:
 *   gcc lab1_p1_cprog.c input.c -o lab1_p1_cprog
 */

#include <stdio.h>
#include "input.h"


#define MIN_ELEMENTS	1
#define MAX_ELEMENTS	1000000
#define BOUND_WORD	65536


int main ()
{
    unsigned int	n;
    unsigned int	num_set[MAX_ELEMENTS];
    unsigned int	i;
    unsigned int	j, k;
    unsigned int	rem;
    unsigned int	mark;

    /* Get n from user at stdin */
    n = get_number (MIN_ELEMENTS, MAX_ELEMENTS);

    i = 0;
    num_set[i++] = 1;
    num_set[i++] = 2;

    /* Find remaining n-2 elements */
    for (j = 3; i < n; j += 2)
    {
	mark = 0;

	for (k = 2; (k < i) && (num_set[k] < BOUND_WORD); k++)
	{
	    rem = j % num_set[k];

	    if (rem == 0)
	    {
		mark = 1;
		break;
	    }
	}

	if (mark == 0) 
	    num_set[i++] = j;
    }

    /* Print out number pattern */
    printf ("\nDisplaying %d elements of pattern:\n    ", n);

    for (i = 0; i < n; i++)
	printf ("%d ", num_set[i]);

    printf ("\n");
}

